<?php

/**
 *  @FileComment            [后台登陆控制器]
 *  @ProjectName             项目名称：shopFrame
 *  @FileName                   文件名称：LoginController.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-5 22:06:02
 *  *
 */
class LoginController extends Controller {

        public function index() {
                //登陆
                if (IS_POST) {
                        $username = Q('post.userName', '', 'trim');
                        $passwd = Q('post.psd', '', 'md5');
                        $verify = Q('post.verify', '', 'strtoupper');
                        $model = K('admin');
                        $data = $model->where(array('adminname' => $username))->find();
                        if ($verify != session('code')) {
                                $this->error('验证码不正确');
                        }
                        if (!$username) {
                                $this->error('用户名不能为空');
                        }
                        if (empty($data) || $data['password'] != $passwd) {
                                $this->error('用户名或者密码不正确');
                        }
                        Rbac::login($username, $passwd, $superadmin = 'admin');
                        $this->success('登陆成功！', U('Index/index'));
                }
                $this->display();
        }

        public function code() {
                //调用验证码
                $code = new Code();
                $code->show();
        }

        public function out() {
                //退出登陆
                session(NULL);
                $this->success('退出成功！');
        }

}
